package com.kui.web;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kui.entity.User;
import com.kui.entity.Wenxian;
import com.kui.service.WenxianService;

public class DelwenxianServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		
		
		if("member".equals(user.getRole())){
			response.sendRedirect("main.jspx");
			return;
		}
		
		String wid = request.getParameter("wid");
		if(wid == null || "".equals(wid) ){
			response.sendRedirect("wenxiancontrol.jspx");
			return;
		}
		
		WenxianService ws =new WenxianService();
		
		Wenxian w = ws.findById(wid);
		if(w == null){
			response.sendRedirect("wenxiancontrol.jspx");
			return;
		}
		
		ws.delById(wid);
		
		 String path = getServletContext().getRealPath("/");
		File file = new File(path +"/upload/" +w.getDownname());
		file.delete();
		response.sendRedirect("wenxiancontrol.jspx");
			
	}

}
